/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler.fixtures;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import se392.ateam2006.meetingmgmt.MeetingMgmtRemote;
import se392.ateam2006.meetingmgmt.meeting.MeetingEntity;
import se392.ateam2006.resourcemgmt.room.RoomEntity;

/**
 *
 * @author Caroline
 */
public class GetBookedMeetings extends fit.RowFixture {

    private MeetingMgmtRemote meetingManage;

    public GetBookedMeetings(MeetingMgmtRemote meetingManage) {
        this.meetingManage = meetingManage;
    }

    @Override
    public Object[] query() throws Exception {
        Collection<MeetingEntity> meetings = meetingManage.getBookedMeetings();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd k:mm");
        ArrayList meetingList = new ArrayList();
        for (MeetingEntity me : meetings) {
            meetingList.add(
                    new BookedMeetingShell(
                    me.getInitiator().getEmail(),
                    me.getId(),
                    format.format(me.getStartDate().getTime()),
                    format.format(me.getEndDate().getTime()),
                    this.extractVenue(me.getRoom())));
        }
        return meetingList.toArray();
    }

    @Override
    public Class getTargetClass() {
        return BookedMeetingShell.class;
    }

    private String extractVenue(RoomEntity room) {
        if (room == null || room.getRoomID() == null) {
            return "";
        } else {
            return room.getRoomID();
        }
    }
}
